﻿using System;

namespace CRMWeb.Utilities.Context
{
    public static class ValidationHelper
    {
        public static bool GetBoolean(object value, bool defaultValue)
        {
            if (value == null || value == DBNull.Value)
            {
                return defaultValue;
            }
            if (value is bool)
            {
                return (bool)value;
            }
            if (value is string)
            {
                var a = value as string;

                if (a == "true" || a == "1")
                {
                    return true;
                }
                if (a == "false" || a == "0")
                {
                    return false;
                }

                return defaultValue;
            }
            return Convert.ToBoolean(value);
        }
    }
}